//index.js
//获取应用实例
var app = getApp();
var Keys = require('../../assets/data/keys.js')
Page({
  data: {
    loadingHidden: false, // loading
    goods: [],
    loadingMoreHidden: true,
  },
  /**
   * 跳转商品详情
   */
  toDetailsTap: function (e) {
      if (app.login_id.length > 0) {
        wx.navigateTo({
          url: "/pages/goods-details/index?id=" + this.data.goods[e.currentTarget.dataset.index].HJP_ID
        })
      } else {
        wx.showModal({
          title: '请登陆',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '../login/index',
              })
            }
          }
        })
      }
  },
  onLoad: function () {
    var that = this    
    that.getGoodsList();
  },
  getGoodsList: function () {
    var that = this;
    wx.request({
      url: Keys.data.url_Home_Product_CXBK_List,
      success: function (res) {
        that.setData({
          goods: res.data.datas,
          loadingMoreHidden: true
        });
        var goods = [];
        if (res.data.code != 0 || res.data.datas.length == 0) {
          that.setData({
            loadingMoreHidden: false,
          });
          return;
        }
        for (var i = 0; i < res.data.datas.length; i++) {
          goods.push(res.data.datas[i]);
        }
        that.setData({
          goods: goods,
        });
      }
    })
  },

})

